<?php
/*
Plugin Name: SyntaxHighlighter 代码高亮
Version: 1.0
Plugin URL:
Description: 可以根据自己要发布的代码语言高亮。
Author: 
Author URL: 
*/

!defined('EMLOG_ROOT') && exit('access deined!');


function et_highlighter()
{
	et_highlighter_open_code();
	echo "<script>
	function insert_et_highlighter(content_data) {
		if (KE.g['content'].wyswygMode == false){
			alert('请先切换到所见所得模式');
		} else {
			KE.insertHtml('content', content_data);
		}
	}
	function et_highlighter_open_code() {
		$('#et_highlighter_wrapper_ajax').toggle();
	}
	function et_highlighter_run() {
		lan_c = $('#et_highlighter_language').val();
		et_code = $('#et_highlighter_code').val();
		if (et_code == '') {
			$('#et_highlighter_wrapper_ajax').toggle();
			return ;
		}
		et_code = et_code.replace('<','&lt;');
		et_str = '<pre class=\"brush: '+lan_c+';\">';
		et_str += et_code;
		et_str += '</pre><br />';
		insert_et_highlighter(et_str);
		
		$('#et_highlighter_code').val('');
		$('#et_highlighter_wrapper_ajax').toggle();
	}
	</script>";
	echo '<span onclick="et_highlighter_open_code();" style="cursor:pointer;">&nbsp;&nbsp;插入代码&nbsp;&nbsp;</span>';
}
function et_highlighter_open_code() {
	$str = '
	<style type="text/css">
		.et_highlighter_wrapper{width: 520px; margin: 10px 15px;font-size: 12px; display:none; position:absolute; background-color:#FFF; border:1px solid #EEE; padding:10px;}
		.et_highlighter_wrapper textarea{width:510px ;height: 300px;resize: none;margin:5px;*margin-left:-12px;}
	</style>
    <div class="et_highlighter_wrapper" id="et_highlighter_wrapper_ajax">
        <p>
            <label for="et_highlighter_language">选择语言</label>
            <select id="et_highlighter_language">
                <option value="as3">ActionScript3</option>
                <option value="bash">Bash/Shell</option>
                <option value="cpp">C/C++</option>
                <option value="css">Css</option>
                <option value="cf">CodeFunction</option>
                <option value="c#">C#</option>
                <option value="delphi">Delphi</option>
                <option value="diff">Diff</option>
                <option value="erlang">Erlang</option>
                <option value="groovy">Groovy</option>
                <option value="html">Html</option>
                <option value="java">Java</option>
                <option value="jfx">JavaFx</option>
                <option value="js">Javascript</option>
                <option value="pl">Perl</option>
                <option value="php">Php</option>
                <option value="plain">Plain Text</option>
                <option value="ps">PowerShell</option>
                <option value="python">Python</option>
                <option value="ruby">Ruby</option>
                <option value="scala">Scala</option>
                <option value="sql">Sql</option>
                <option value="vb">Vb</option>
                <option value="xml">Xml</option>
            </select> <input type="button" name="button" id="button" value="确定" onclick="et_highlighter_run();" /> <input type="button" name="button" id="button" value="关闭" onclick="$(\'#et_highlighter_code\').val(\'\');$(\'#et_highlighter_wrapper_ajax\').toggle();" />
        </p>
        <label for="et_highlighter_code"></label><textarea id="et_highlighter_code" cols="" rows=""></textarea>
	</div>
	';
	echo $str;
}
addAction('adm_writelog_head', 'et_highlighter');

function et_highlighter_content() {
	echo '
	<script type="text/javascript" src="'.BLOG_URL.'content/plugins/et_highlighter/shCore.js"></script>
	<link type="text/css" rel="stylesheet" href="'.BLOG_URL.'content/plugins/et_highlighter/shCoreDefault.css"/>
	<script type="text/javascript">SyntaxHighlighter.all();</script>
	';
}

addAction('index_head', 'et_highlighter_content');

function et_highlighter_temp() {
	echo '<div style="display:none;">et_highlighter</div>';
}
addAction('log_related','et_highlighter_temp');
?>